package com.beyondsoft.mcms.domain;

import java.util.Date;
import java.util.List;

import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.tostring.RooToString;

@RooJavaBean
@RooToString
@RooJpaActiveRecord
public class Suggest {

	/**
     */
	@Temporal(TemporalType.TIMESTAMP)
	@DateTimeFormat(style = "M-")
	@NotNull
	private Date suggestDate;

	/**
     */
	@NotNull
	@Size(max = 300)
	private String suggestion;

	/**
     */
	@NotNull
	@ManyToOne
	private MemberInfo proposer;

	/**
     */
	@ManyToOne
	private Users reply;

	/**
     */
	@Temporal(TemporalType.TIMESTAMP)
	@DateTimeFormat(style = "M-")
	private Date replyDate;

	/**
     */
	@Size(max = 300)
	private String replyContent;

	public static List<Suggest> findAllSuggests() {
		return entityManager().createQuery("SELECT o FROM Suggest o order by o.suggestDate desc", Suggest.class)
				.getResultList();
	}

	public static List<Suggest> findSuggestEntries(int firstResult, int maxResults) {
		return entityManager().createQuery("SELECT o FROM Suggest o order by o.suggestDate desc", Suggest.class)
				.setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
	}
}
